package de.tuberlin.dima.dkey.tmp;

import java.io.IOException;
import java.util.concurrent.BlockingQueue;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import de.tuberlin.dima.dkey.client.Client;
import de.tuberlin.dima.dkey.client.GTree;
import de.tuberlin.dima.dkey.client.KeyValue;
import de.tuberlin.dima.dkey.util.GNode;

public class CreateGraph {

	static Logger logger = Logger.getLogger(CreateGraph.class);
	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {

		//Set up the logging
	    BasicConfigurator.configure();
		Logger.getRootLogger().setLevel(Level.INFO);
		
		GTree tree = new GTree();
		
		GNode a = tree.addNewNodeWithValues("A");
		GNode b = tree.addNewNodeWithValues("B");
		GNode c = tree.addNewNodeWithValues("C");

		tree.addEgdeWithValues(a, b, "x");
		tree.addEgdeWithValues(a, c, "y");

		if (tree.isValid()){
			//Send it to the server
			Client client = new Client("localhost", 8080);
			try {
				
				client.addTree(tree);

				BlockingQueue<String> answer = client.getReturnQueue();
				System.out.println(answer.take());
				
				client.commit();
				
				client.end();


			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}else{
			System.err.print("Tree is not valid");
		}
	}

}
